/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Comunicacion;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;

/**
 *
 * @author michael
 */
public class ListenerFactory {
    public static final int PORT = 1234;
    private Vector<Listener> listeners;
    ListenerFactory() throws IOException{
        listeners = new Vector<Listener>();
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(PORT);
        } catch (IOException e) {
            System.err.println("Could not listen on port: 4444.");
            System.exit(1);
        }
        Socket clientSocket = null;
        while(true){
            try {
                clientSocket = serverSocket.accept();
                System.out.println("client socket created");
            } catch (IOException e) {
                System.err.println("Accept failed.");
                System.exit(1);
            }
            Listener actual = new Listener(clientSocket);
            new Thread(actual).start();
            listeners.add(actual);
        }
    }
    public static void main(String[] args){
        try{
            ListenerFactory fact = new ListenerFactory();
        }catch(IOException e){
            System.err.println("not able to build Listener Factory");
        }
    }
}
